<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>2018/12/25</title>
    <!--好的代码像粥一样,是得用时间和精力熬的。-->
</head>
<body>

</body>
<script>
    var arr = [23,32,54,65,786,23,3,4,78,9,76,4,8,9,2,3,44,65];
    var num = 6;//分割线
    function swap(arr,i,j) {
       var temp = arr[i];
       arr[i] = arr[j];
       arr[j] = temp;
    }
    var i = 0; //指针
    var left = -1; //数组从0开始，所以数组左边第一位是-1
    var right = arr.length;//数组最大长度为arr.length-1,数组右边第一位arr.length
    while(i!==right){
     if(arr[i]<num){
         left++;
         swap(arr,i,left);
         i++;
     }
     if(arr[i] === num){
         i++;
     }
     if(arr[i]>num){
         right--;
         swap(arr,i,right);
     }
    }
    console.log(arr);
</script>
</html>
